﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ApproveFlowEngine.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace ApproveFlowEngine.EntityFrameworkCoreSplitTable.EFCore.Core
{
    public class SplitModelCacheKeyFactory : ModelCacheKeyFactory
    {
        public SplitModelCacheKeyFactory(ModelCacheKeyFactoryDependencies dependencies) : base(dependencies)
        {
        }

        public override object Create(DbContext context)
        {
            if (context is SplitDbContext)
            {
                return $"{context.GetType().Name}_{TableTailHelper.GetKey()}";
            }
            else
            {
                return base.Create(context);
            }
        }

        public override object Create(DbContext context, bool designTime)
        {
            if (context is SplitDbContext)
            {
                return $"{context.GetType().Name}_{TableTailHelper.GetKey()}_{designTime}";
            }
            else
            {
                return base.Create(context, designTime);
            }
        }
    }
}